(function($) {
	$(document).ready(function() {
		$("#email").focus();
		$("#submit_btn ,#login_btn , #confirm, #confirm_num, #loading, #pwdFind_btn").hide();
		$("#confirm_btn").click(function(){
			var regExp = /[0-9a-zA-Z][_0-9a-zA-Z-]*@[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+){1,2}$/;
			if($("#email").val().length == 0){
				var message = "이메일을 입력해주세요.";
				$("#email_insert_result").html(message);
				return false;
			}else if(!$("#email").val().match(regExp)){
				var message = "이메일 형식이 올바르지 않습니다.";
				$("#email_insert_result").html(message);
				return false;
			}else{
				$.ajax({
					url : "confirm_send.do",
					type : "post",
					data : {"email":$("#email").val()},
					dataType : "text",
					beforeSend : function(){
						$("#loading").show().fadeIn('fast');
					},
					success : function(data){
						$("#email").readOnly="readonly";
						var data = eval('('+data+')');
						var message = data.message;
						var confirmNum = data.confirmNum;
						if(confirmNum != null){
							$("#confirm ,#confirm_num ,#submit_btn").show();
							$("#submit_btn").click(function(){
								if($("#confirm_num").val() == confirmNum){
									document.joinCheck_form.action = "join_agree.do";
								}else if($("#confirm_num").val() == (null || "")){
							    	var message = "인증번호를 입력하세요";
							    	$("#message").html(message);
							    	document.joinCheck_form.confirm_num.focus();
							    	return false;
							    }else{
							    	var message = "인증번호가 일치하지 않습니다.";
							    	$("#message").html(message);
							    	$("#confirm_num").val("");
							    	document.joinCheck_form.confirm_num.focus();
							    	return false;
							    }
							});
						}
						else{
							$("#login_btn").show();
							$("#message").html(message);
							document.joinCheck_form.action = "loginGo.do";
						}
						var mailname = data.mailname;
						$("#message").html(message);
						if(mailname == "naver.com"){
								var link1 = "<a href='http://www.naver.com' target=_blank>네이버로 이동</a>";
						    	$("#portal").html(link1);
						}
						else if(mailname == "nate.com"){
								var link2 = "<a href='http://www.nate.com' target=_blank>네이트로 이동</a>";
								$("#portal").html(link2);
						}	
						else if((mailname == "daum.net") || (mailname == "hanmail.net")){
								var link3 = "<a href='http://www.daum.net' target=_blank>다음으로 이동</a>";
								$("#portal").html(link3);
						}
					},
					complete : function(){
						$("#loading").fadeOut('fast');
						document.joinCheck_form.email.readOnly = true;
					},
					error : function(e){
						alert("오류나써요");
					}
				});
			}
		});
	});
})(jQuery);
